package com.china08.yxyapi.api.home.resource;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.china08.yxyapi.api.YxyApiBaseController;
import com.china08.yxyapi.model.YxyApiReqModel;
import com.china08.yxyapi.model.YxyApiRespModel;
import com.china08.yxyapi.service.yxyresource.YxyResourceService;

import io.swagger.annotations.ApiOperation;

/**
 * 下载数增加
 */
@CrossOrigin
@RestController
public class ResourceDownloadNumberController extends YxyApiBaseController {

    @Autowired
    private YxyResourceService yrs;

    @ApiOperation(value = "资源下载次数增加")
    @ResponseBody
    @RequestMapping(value = "/api_yw/home/res/downloadnumber", method = RequestMethod.PUT, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public RespModel precess(HttpServletRequest request, HttpServletResponse response, @RequestBody ReqModel reqModel) {
        RespModel model = new RespModel();
        yrs.resDownLoadNumberPlus(reqModel.id);
        model.setMessage("成功");
        return model;
    }

    protected static class ReqModel extends YxyApiReqModel {
        public String id;

        @Override
        public void autoCheck() {
            Assert.notNull(StringUtils.defaultIfBlank(id, null), "没有指定资源");
        }

    }

    protected static class RespModel extends YxyApiRespModel {

    }
}
